﻿//
// Created by francklinson on 2021/3/24.
//

#ifndef CPPPRIMERPLUSREADINGCODES_STRINGGoodGOOD_H
#define CPPPRIMERPLUSREADINGCODES_STRINGGoodGOOD_H

#include <iostream>

using std::ostream;
using std::istream;

class StringGood
{
private:
    char *str;                    // pointer to stringGood
    int len;                       // length of stringGood
    static int num_strings;    // number of objects
    static const int CINLIM = 80;  // cin input limit
public:
// constructors and other methods
    StringGood(const char *s);       // constructor
    StringGood();                     // default constructor
    StringGood(const StringGood &);   // copy constructor
    ~StringGood();                    // destructor
    int length() const
    { return len; }

// overloaded operator methods
    StringGood &operator=(const StringGood &);

    StringGood &operator=(const char *);

    char &operator[](int i); // 可读写
    const char &operator[](int i) const; // 只读
// overloaded operator friends
    friend bool operator<(const StringGood &st, const StringGood &st2);

    friend bool operator>(const StringGood &st1, const StringGood &st2);

    friend bool operator==(const StringGood &st, const StringGood &st2);

    friend ostream &operator<<(ostream &os, const StringGood &st);

    friend istream &operator>>(istream &is, StringGood &st);

// static function
    static int HowMany(); // 静态成员函数  只能读取静态成员参数
};

#endif //CPPPRIMERPLUSREADINGCODES_STRINGGoodGOOD_H
